package com.example.demo.socket;

import org.springframework.stereotype.Component;

import javax.websocket.*;
import javax.websocket.server.PathParam;
import javax.websocket.server.ServerEndpoint;

/*
 *
 *   @Author:Sjy
 *   @Date: 2024/3/26-03-26-21:18
 *   礼物长链接特效
 */
@Component
//定义此类是WS的服务器端
@ServerEndpoint("/gift/{name}")
public class GiftSocketServer {
    /**
     * 连接建立成功时触发
     * @param session 当前会话
     */
    @OnOpen
    public void onOpen(Session session, @PathParam("name")String name){}
    /**
     * 连接关闭时触发
     */
    @OnClose
    public void onClose(@PathParam("name")String name){}
    /**
     * 收到客户端消息时触发
     * @param message
     */
    @OnMessage
    public void onMessage(String message, @PathParam("name")String name){}

    /**
     * 发生错误时触发
     * @param error
     */
    @OnError
    public void onError(Throwable error,@PathParam("name")String name){}

}
